home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************************
- ExampleModule.c
-
-
- DOCUMENTATION
-
- an example module for Meddle, the Fat Binary
-
-
- MODULE CODE RESOURCES
-
- HISTORY
-
- Copyright )WORK-IN_PROGRESS Noesis Software Construction
- **********************************************************************************/
-
- #include <Memory.h>
-
- #include "ModuleRoutines.h"
- #include "Jules.h"
-
- // ANSI math functions use globals, so we need to set up A4 (I think)
- // Actually, it seems to work fine without it . . .
- //#include "A4Stuff.h"
- //#include "SetupA4.h"
-
- short GetBestRect( Rect *r);
-
- //*********************************************************************************
- // ModOpen
- //*********************************************************************************
- OSErr main( ModuleParamBlkPtr mpPtr)
- {
- OSErr err = noErr;
- JulesDataPtr julePtr = nil;
- Rect dstR;
- short pixD;
-
- // allocate proc pointers
- if ( (err=InitmProcs(mpPtr)) != noErr)
- return err;
-
- // If you have your own About proc defined, use the following line
- //mpPtr->mProcs.aboutProc = NewModAboutProc( ABOUTPROCNAME);
-
- // Allocate our private storage
- julePtr = (JulesDataPtr)NewPtrClear(sizeof(JulesData));
- err = MemError();
- if (err != noErr)
- goto error;
-
- // Set it up
- pixD = 1;
- if ( mpPtr->mInPreview) {
- InitJules(julePtr, &mpPtr->mGraf->portRect);
- } else {
- pixD = GetBestRect( &dstR);
- InitJules(julePtr, &dstR);
- }
-
- // Check color environment
- if ( pixD > 1)
- julePtr->useColor = true;
- else
- julePtr->useColor = false;
-
- // store private data in extended window record
- mpPtr->mStorage = (long)julePtr;
-
- // done
- return noErr;
-
- error:
- if (julePtr != nil)
- DisposPtr((Ptr)julePtr);
-
- return err;
- }
-
- //*********************************************************************************
- short GetBestRect( Rect *r)
- {
- short bestPixSiz;
- short mostNegH, mostNegV;
- Rect bestR;
- GDHandle device;
-
- bestPixSiz = 0;
- bestR.left = bestR.right = bestR.top = bestR.bottom = 0;
- mostNegH = mostNegV = 0;
-
- for (device = GetDeviceList(); device != 0; device = GetNextDevice(device)) {
- if (TestDeviceAttribute(device, screenDevice)
- && TestDeviceAttribute(device, screenActive)) {
-
- // Most Colors wins
- if ( (**(**device).gdPMap).pixelSize > bestPixSiz ) {
- bestPixSiz = (**(**device).gdPMap).pixelSize;
- bestR = (**device).gdRect;
- }
- // Adjust for monitors to the left of the Main Device
- if ( (**device).gdRect.left < mostNegH) mostNegH = (**device).gdRect.left;
- if ( (**device).gdRect.top < mostNegV) mostNegV = (**device).gdRect.top;
- }
- }
-
- *r = bestR;
- r->left -= mostNegH; r->right -= mostNegH;
- r->top -= mostNegV; r->bottom -= mostNegV;
-
- return bestPixSiz;
- }
-
-
- //*********************************************************************************
- // ModDraw
- //
- // The Port is set for you on entry. Have fun !
- //
- //*********************************************************************************
- OSErr ModDraw( ModuleParamBlkPtr mpPtr)
- {
- JulesDataPtr julePtr = (JulesDataPtr)mpPtr->mStorage;
- // long oldA4 = SetUpA4();
-
- //PenSize(2, 2);
- GetNextPoint(julePtr);
- JuliaStep(julePtr, 10, false); // Throw away first few points
- JuliaStep(julePtr, 30, true); // Draw a bunch
- if(Random() % 20 == 0)
- JuliaStep(julePtr, julePtr->numJuliaPts, true); // Once in a while, do 'em all
-
- // RestoreA4(oldA4); // restore A4 to saved value before returning
- return noErr;
- }
-
-
- //*********************************************************************************
- // ModClose
- //
- // Clean-up after the party...
- //
- //*********************************************************************************
- OSErr ModClose( ModuleParamBlkPtr mpPtr)
- {
- JulesDataPtr julePtr = (JulesDataPtr)mpPtr->mStorage;
-
- if (julePtr) {
- DisposPtr((Ptr)julePtr);
- mpPtr->mStorage = nil;
- }
-
- return MemError();
- }
-
-
- //*************************************************
- // Sample About Procedure for a Module
-
- OSErr ABOUTPROCNAME( ModuleParamBlkPtr mpPtr);
- OSErr ABOUTPROCNAME( ModuleParamBlkPtr mpPtr)
- {
- Rect tmpR;
- EventRecord evt;
- JulesDataPtr data;
-
- data = (JulesDataPtr)mpPtr->mStorage;
-
- // GrafPort is set on entry
- tmpR = mpPtr->mGraf->portRect;
- EraseRect( &tmpR);
-
- if ( GetPortPixDepth( mpPtr->mGraf) > 1)
- ForeColor( redColor);
- else
- ForeColor( whiteColor);
- PaintRect( &tmpR);
-
- while ( !WaitNextEvent( mDownMask+keyDownMask, &evt, GetCaretTime(), 0))
- ;
-
- ForeColor( blackColor);
- PaintRect( &tmpR);
-
- return;
- }
-
-
- //*************************************************
- OSErr ModChangePrefs( ModuleParamBlkPtr mpPtr)
- {
- JulesDataPtr julePtr;
- long **tIDh;
- long tmp;
- short val;
-
- // We get passed in a ptr to the ModControlRecord in
- // the mInfo fld. Our only clue to which control type
- // this is is by the first long in every ModControlRec,
- // the User-Defined ID number !
-
- //Debugger();
-
- julePtr = (JulesDataPtr)mpPtr->mStorage;
- tIDh = (long**)mpPtr->mInfo;
-
- switch (**tIDh) {
- case 1: // Slider
- {
- ScSLD_SliderRec **tScSLD_RecH;
- // we have a horizSlider
-
- tScSLD_RecH = (ScSLD_SliderRec **)mpPtr->mInfo;
- val = (*tScSLD_RecH)->curValue;
- // map 0-100 to kNumJuliaPts/4 to kNumJuliaPts*2
- // x/100 * 1.75k + .25k
- tmp = val/100 * 7 * kNumJuliaPts + (kNumJuliaPts >> 1);
- julePtr->numJuliaPts = tmp >> 3;
-
- }
- break;
-
- };
-
- return noErr;
- }
-
-
-
-
- //**********************************************************************************
- // E N D O F L I S T I N G E N D O F L I S T I N G